$(document).ready(function() {
    $(".main-menu").click(function() {
        if ($(this).parent().hasClass("clicked-admin-menu")) {
            $(this).parent().removeClass("clicked-admin-menu");
        } else {
            $(this).parent().addClass("clicked-admin-menu");
        }
    });

    $("#master_check").click(function(event){
        var target = event.target;
        $("#tbl_list").find("input[type='checkbox']").each(function(){
            $(this).prop("checked", $(target).prop("checked"));
        });
    });

    $(".deactive-item-button, .active-item-button").click(function(e){
        var target = $(e.target);
        var id = target.attr("data-id");
        var active = target.attr("data-active");
        var url = target.attr("data-url");
        $.ajax({
            url: url,
            method: "post",
            data: {id:id,active:active},
            success:function(resp) {
                window.location.reload(true);
            }
        });

    });
    
    $("#frm_search_user").submit(function() {
        var search_name = $("#search_name").val();
        var redirect_url = base_url + "/admin/index/users";
        if (search_name !== '') {
            redirect_url += "/search_name/" + search_name;
        }
        window.location.href = redirect_url;
        return false;
    });
    
});